<?php
header("Content-type: text/javascript; charset=utf8");

include_once "config.php";

define( "D_FOLDER", "decor/" );
define( "D_SITE", "http://ok.onlife.mobi/".D_FOLDER );

$ret = array("error"=>0);
$db->real_query('SELECT * FROM `decor` ORDER BY `id` DESC LIMIT 0, 50');

$q = $db->store_result();

if ( $q && $q->num_rows > 0 )
{
	$ret['decor'] = array();
	while ( $arr = $q->fetch_array( MYSQLI_ASSOC ) ) {
		if ( !file_exists( D_FOLDER.$arr['url']) ) continue;
		$ret['decor'][] = array( "id"=>$arr['id'],
									//"name"=>iconv("CP1251","UTF-8",$arr['title']),
									"name"=>$arr['title'],
									"url"=>D_SITE.$arr['url'] );
	}
	
}
else
{
	$ret['error'] = 12;
	$ret['description'] = 'Failed to execute the query';
}


echo json_encode($ret);
